# 视频课程
# https://www.bilibili.com/video/BV1Sz4y1U77N/

# 基础容器
# https://blog.csdn.net/2401_87290252/article/details/154709431

# 打印如何不换行
print("hello ", end="")
print("world")

# # 输入
# a = input()
# a = input("请输入：")
# # 默认输入类型为字符串，可指定类型
# a = int(input("请输入"))

a = 10
b = str(a)
c = float(a)

# 生成随机数
import random

ra = random.randint(1, 100)  # 生成包含1和100的整数
rb = random.uniform(1, 100)  # 生成小数
rc = random.random()  # 生成0到1之间的小数

# 次方
a = 2
a **= 10  # a的10次方

# 与或非 and or not
f = False
t = not f  # True
o = f or t
an = f and t

# 字符串拼接
s1 = "P"
s2 = "YY"
pyy = s1 + s2
pp = s1 * 2
ppyy = s1 * 2 + s2
print(pyy)
print(pp)
print(ppyy)

# 条件分支语句
a = 11
b = a % 2
c = b == 0
if c:
    print("是偶数")
else:
    print("不是偶数")

# a = int(input("输入分数："))
if a < 0 or a > 100:
    print("非法分数")
elif a < 60:
    print("不合格")
else:
    print("合格")

# 循环
a = 0
while a < 10:
    a += 1
    if a == 5:
        continue
    print(f"{a} ", end="")
    if a == 8:
        break
print("end")

for i in range(10):
    print("hello", end=" ")
print("world")

arr = [1, 3, 5, 7, 9]
for i in arr:
    print(i, end=" ")
print()

str1 = "ABCDEFG"
for i in str1:
    print(i, end=" ")
print()

r1 = range(5)  # [0, 5)
print(type(r1))  # <class 'range'>
r2 = range(-1, 6)  # [-1, 6)
print(r2)  # range(-1, 6)

for i in range(10):
    print(i, end=" ")
    if i == 5:
        break
else:  # 如果不是被break打破，就会执行else里面的内容
    print("exit true")

print()

a = 0
while a < 10:
    a += 1
    print(a, end=" ")
else:
    print("exit true")

# 切片
s = "my name is python"
s = s[1:5]  # 左闭右开，类比substr
# 不写左边表示从头开始截取，不写右边表示截取到最后，列表都不写表示截取全部
# 如果写第三个参数就表示截取步长，每隔n个数截取一次
print(s)

s = "my name is python"
# 替换字符串的某一段
s = s.replace("python", "cpp")
print(s)  # my name is cpp
# 根据字符进行分割，并使用列表保存
arr = s.split(" ")
print(arr)  # ['my', 'name', 'is', 'cpp']

string2 = "-".join(arr)
print(string2)  # my-name-is-cpp

# 转换大小写
a = "hello".capitalize()  # 将字符串第一个字母转换成大写
a = "hello".title()  # 将字符串每个单词首字母转换成大写
a = "hello".lower()  # 将字符串中大写转小写
a = "hello".upper()  # 将字符串中小写转大写

# 删除空白字符
b = "      hello".lstrip()  # 删除字符串左侧空白字符
b = "hello      ".rstrip()  # 删除字符串右侧空白字符
b = "   hello   ".strip()  # 删除字符串两侧空白字符

# 下标访问
string3 = "python"
c = string3[0]  # p
arr = [1, 2, 3, 4]
a = arr[0]  # 1

# 嵌套列表
array = [[1, 2, 3], [4, 5], [6, 7, 8]]
arr1 = array[0]  # [1,2,3]
num1 = array[0][1]  # 2

array = [
    [[1, 2, 3], [4, 5], [6, 7, 8]],
    [[1, 1], [4, 5], [1, 4]]
]

for a in array:
    for b in a:
        for c in b:
            print(c, end=" ")
    print()

# 列表能存放任何类型数据
b = 12
a = [1, False, "happy", b, [1, 2, 3]]
if 1 in a:
    print("in")
if 1 not in a:
    print("not in")
# 增加
a.append("abc")
a.insert(1, 't')
# 修改
a[0] = 0
# 删除
a.pop(0)
a.remove("happy")
a.clear()
del a
# string是不可变类型
string4 = "pypy"
# string4[0] = 'c'  # 报错


b = 12
a = [1, False, "happy", b, [1, 2, 3]]
# 浅拷贝
# b = a
# 深拷贝
b = a.copy()

# 排序
a = [4, 2, 1, 3]
a.sort()  # 直接修改a中元素
a = sorted(a)  # 不修改a中元素，使用返回值返回排序结果
del a

# 元组 const vector
a = (1, 2)
# a[0] = 1  # 元组不支持修改，只能访问
a = (1, 2, "22", True)
print(a)
for i in a:
    print(i, end=" ")
print()

for i in range(len(a)):
    print(a[i], end=" ")
print()

# 集合 unordered_set
# 无序性，不重复性
s = {1, 3, 3, 4, 2}
print(s)

# 字典 key-value unordered_map
d = {"name": "Mike", "age": 10, "grade": (90, 80, 100)}
print(d)
# 获得所有的键、值、键值对
d.keys()
d.values()
d.items()
# 打印，类比范围for
for k, v in d.items():
    print(k, end=":")
    print(v, end="\t")
print()

# 集合和字典都用{}，那么下面这个表示什么？
a = {}  # 表示空字典
a = set()  # 表示空集合

# 修改字典元素
d = {"name": "Mike", "age": 10, "grade": (90, 80, 100)}
print(d["name"])
d["name"] = "Lily"
del d["age"]
d.clear()
del d


# 函数
def func():
    print("这是一个函数")


def isBigger10(n):
    # if n > 10:
    #     return True
    # else:
    #     return False
    return n > 10


num = 15
if (isBigger10(num)):
    print(f"{num} > 10")
else:
    print(f"{num} < 10")

DAY = 0


def day():
    global DAY  # 使用全局变量
    if DAY % 2 == 0:
        print("==0")
    else:
        print("!=0")


day()

del a, b


def add(add1: int, add2: int):
    """
    用于返回两个数相加的值
    :param add1: 第一个加数
    :param add2: 第二个加数
    :return: 返回整型
    """
    return add1 + add2


def g():
    return 1, 2  # 返回的是一个元组


b = g()
g1, g2 = g()  # 拆包，用两个元素分别接收元组两个值


# 不定长参数，默认参数
def func2(n=10, *args, **kwargs):  # 包裹位置参数，包裹关键字参数
    print(n, end=" ")
    for i in args:
        print(i, end=" ")
    print(kwargs["ns"])
    print(kwargs["nt"])
    print()


func2(1, 3, 2, 5, 4, ns=15, nt=16)
